Maximum Segment Sum, Monadically (distilled tutorial, with solutions)

نویسنده

  • Jeremy Gibbons
چکیده

The maximum segment sum problem is to compute, given a list of integers, the largest of the sums of the contiguous segments of that list. This problem specification maps directly onto a cubic-time algorithm; however, there is a very elegant linear-time solution too. The problem is a classic exercise in the mathematics of program construction, illustrating important principles such as calculational development, pointfree reasoning, algebraic structure, and datatype-genericity. Here, we take a sideways look at the datatype-generic version of the problem in terms of monadic functional programming, instead of the traditional relational approach; the presentation is tutorial in style, and leavened with exercises for the reader.

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Maximum Segment Sum, Monadically (distilled tutorial)

The maximum segment sum problem is to compute, given a list of integers, the largest of the sums of the contiguous segments of that list. This problem specification maps directly onto a cubic-time algorithm; however, there is a very elegant linear-time solution too. The problem is a classic exercise in the mathematics of program construction, illustrating important principles such as calculatio...

متن کامل

An Optimal Algorithm for the Range Maximum-Sum Segment Query Problem

We are given a sequence A of n real numbers which is to be preprocessed. In the Range Maximum-Sum Segment Query (RMSQ) problem, a query is comprised of two intervals [i, j] and [k, l] and our goal is to return the maximum-sum segment of A where the staring index of the segment lies in [i, j] and the ending index lies in [k, l]. We provide the ̄rst known optimal algorithm with O(n) preprocessing...

متن کامل

On the Range Maximum-Sum Segment Query Problem

We are given a sequence A of n real numbers which is to be preprocessed. In the Range Maximum-Sum Segment Query (RMSQ) problem, a query is comprised of two intervals [i, j] and [k, l] and our goal is to return the maximum-sum segment of A whose starting index lies in [i, j] and ending index lies in [k, l]. We propose the first known algorithm for this problem in O(n) preprocessing time and O(1)...

متن کامل

Bronchial hyperreactivity in response to inhalation of ultrasonically nebulised solutions of distilled water and saline.

To assess non-specific bronchial reactivity the effect of inhaling ultrasonically nebulised solutions of distilled water and hypotonic (0.3%), isotonic (0.9%), and hypertonic (2.7%, 3.6%) saline was investigated in 10 asthmatic patients and nine normal subjects. Expired ventilation and the maximum percentage fall in forced expiratory volume in one second (FEV1) were recorded. The sensitivity to...

متن کامل

Algorithms for the Problems of Length-Constrained Heaviest Segments

We present algorithms for length-constrained maximum sum segment and maximum density segment problems, in particular, and the problem of finding length-constrained heaviest segments, in general, for a sequence of real numbers. Given a sequence of n real numbers and two real parameters L and U (L 6 U), the maximum sum segment problem is to find a consecutive subsequence, called a segment, of len...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2011